from __future__ import annotations

from dataclasses import dataclass
from math import exp


@dataclass
class TemperatureStress:
    peak_temp_rise_C: float
    thermal_stress_MPa: float
    note: str


def mass_concrete_temp_stress(cement_content_kg_m3: float, adiabatic_rise_coeff_C: float = 60.0, decay_coeff_per_day: float = 0.25, youngs_modulus_MPa: float = 30000.0, thermal_expansion_per_C: float = 1.0e-5, restraint_ratio: float = 0.7, delta_T_C: float | None = None) -> TemperatureStress:
    """大体积混凝土温控与温度应力（简化）：

    - 绝热温升近似: ΔT_ad(t) = T_max * (1 - e^{-k t})，取峰值近似为 T_max
    - 温度应力: σ ≈ E · α · ΔT · β（β为约束系数）
    若传入 delta_T_C 直接使用，否则以 adiabatic_rise_coeff_C 的比例估算。
    """

    T_max = adiabatic_rise_coeff_C * (cement_content_kg_m3 / 350.0)
    peak = T_max if delta_T_C is None else delta_T_C
    sigma = youngs_modulus_MPa * thermal_expansion_per_C * peak * restraint_ratio
    return TemperatureStress(peak_temp_rise_C=peak, thermal_stress_MPa=sigma, note="需结合测温与约束条件校核")


